<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$lotto_id = intval( $_POST['lotto_id'] );
$bettype = 12;
$backs = $_POST['b91'];
$money = intval( $_POST['b92'] );
$account = $_POST['account'];
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
if ( $money <= 0 )
{
    err( "金额错误！" );
}
if ( 15 < $backs )
{
    err( "不合理的退水！" );
}
$err = 0;
$allnum = 0;
$chknum = array( 0, 0, 0, 0, 0, 0, 0 );
$bets = array();
$i = 1;
while ( $i <= 6 )
{
    if ( isset( $_POST["r".$i."_1"] ) )
    {
        if ( $_POST["r".$i."_1"] == 1 && 0 < $_POST["r12_".$i."_1"] )
        {
            $bets[$allnum] = $i."_1_".$_POST["r12_".$i."_1"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
        else if ( $_POST["r".$i."_1"] == 2 && 0 < $_POST["r12_".$i."_2"] )
        {
            $bets[$allnum] = $i."_2_".$_POST["r12_".$i."_2"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
    }
    if ( isset( $_POST["r".$i."_2"] ) )
    {
        if ( $_POST["r".$i."_2"] == 1 && 0 < $_POST["r12_".$i."_3"] )
        {
            $bets[$allnum] = $i."_3_".$_POST["r12_".$i."_3"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
        else if ( $_POST["r".$i."_2"] == 2 && 0 < $_POST["r12_".$i."_4"] )
        {
            $bets[$allnum] = $i."_4_".$_POST["r12_".$i."_4"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
    }
    if ( isset( $_POST["r".$i."_3"] ) )
    {
        if ( $_POST["r".$i."_3"] == 1 && 0 < $_POST["r12_".$i."_5"] )
        {
            $bets[$allnum] = $i."_5_".$_POST["r12_".$i."_5"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
        else if ( $_POST["r".$i."_3"] == 2 && 0 < $_POST["r12_".$i."_6"] )
        {
            $bets[$allnum] = $i."_6_".$_POST["r12_".$i."_6"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
        else if ( 0 < $_POST["r12_".$i."_7"] )
        {
            $bets[$allnum] = $i."_7_".$_POST["r12_".$i."_7"];
            ++$allnum;
            ++$chknum[$i];
            if ( 2 < $chknum[$i] )
            {
                ++$err;
            }
        }
    }
    ++$i;
}
if ( $allnum < 2 )
{
    err( "过关至少需选择二种玩法！" );
}
if ( 0 < $err )
{
    err( "每个号码最多只能选择二种玩法！" );
}
$numbers = "";
$i = 0;
while ( $i < $allnum )
{
    $numbers .= $bets[$i].",";
    ++$i;
}
$numbers = substr( $numbers, 0, 0 - 1 );
$fields = array();
$fields['lotto_id'] = $lotto_id;
$fields['createtime'] = systime();
$fields['bettype'] = $bettype;
$fields['numbers'] = "'{$numbers}'";
$fields['line_nums'] = "'{$numbers}'";
$fields['amount'] = $money;
$fields['rate'] = 0;
$fields['back'] = $backs;
$fields['account'] = "'".$account."'";
db_insert( "bet8", $fields );
echo "<p>走飞成功！</p>";
echo "<p><input type=button value='回上一页' onclick='history.back()'></p>";
echo "<script>";
echo "setTimeout(\"location.href='op.php?op=admin&fp=unow9&select={$selectid}'\",3000);";
echo "</script>";
?>